﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Web;

using edowork.com.SQL2005;

namespace WebInvoicingsys
{
    /// <summary>
    /// 取得系统中不同项的流水号
    /// </summary>
    public class SysID
    {
        public static string md532(string str)
        {
            return System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(str, "MD5").ToLower();  
        }

        /// <summary>
        /// 取得权限组编码的流水号
        /// </summary>
        /// <param name="connectionString"></param>
        /// <param name="error_msg"></param>
        /// <returns></returns>
        public static string SCR_RoleID(string connectionString, ref string error_msg)
        {
            using (edowork.com.SQL2005.TranUtil tranutil = new TranUtil(connectionString))
            {
                System.Data.SqlClient.SqlTransaction tran = null;

                try
                {
                    tran = tranutil.GetSqlTransaction();
                }
                catch(Exception er)
                {
                    error_msg = er.Message;
                    return null;
                }

                edowork.com.SQL2005.Execute exec = new Execute(connectionString);

                string sql = "";
                int result = -1;
                
                //更新流水号加1
                sql = "update SCR set indexs = indexs + 1 where Remark='权限组'";

                result = exec.ExecSQLQueryInt(sql, ref error_msg, tran);

                if (result <= 0)
                {
                    tran.Rollback();
                    tranutil.CloseConnection();
                    return null;
                }

                //取得流水号
                sql = "select * from SCR where Remark='权限组'";

                DataSet dsresult = exec.ExecSQLQueryDataSet(sql, ref error_msg, tran);

                if ((dsresult == null) || (dsresult.Tables.Count <= 0) || (dsresult.Tables[0].Rows.Count != 1))
                {
                    tran.Rollback();
                    tranutil.CloseConnection();
                    return null;
                }

                int indexs = 0;

                if (Int32.TryParse(dsresult.Tables[0].Rows[0]["indexs"].ToString(), out indexs) == false)
                {
                    tran.Rollback();
                    tranutil.CloseConnection();
                    return null;
                }

                tran.Commit();
                tranutil.CloseConnection();

                return (dsresult.Tables[0].Rows[0]["Codeing"].ToString() + indexs.ToString()).Trim().ToString();
            }
        }

        /// <summary>
        /// 取得用户编码的流水号
        /// </summary>
        /// <param name="connectionString"></param>
        /// <param name="error_msg"></param>
        /// <returns></returns>
        public static string SCR_SysuserID(string connectionString, ref string error_msg)
        {
            using (edowork.com.SQL2005.TranUtil tranutil = new TranUtil(connectionString))
            {
                System.Data.SqlClient.SqlTransaction tran = null;

                try
                {
                    tran = tranutil.GetSqlTransaction();
                }
                catch (Exception er)
                {
                    error_msg = er.Message;
                    return null;
                }

                edowork.com.SQL2005.Execute exec = new Execute(connectionString);

                string sql = "";
                int result = -1;

                //更新流水号加1
                sql = "update SCR set indexs = indexs + 1 where Remark='用户编码'";

                result = exec.ExecSQLQueryInt(sql, ref error_msg, tran);

                if (result <= 0)
                {
                    tran.Rollback();
                    tranutil.CloseConnection();
                    return null;
                }

                //取得流水号
                sql = "select * from SCR where Remark='用户编码'";

                DataSet dsresult = exec.ExecSQLQueryDataSet(sql, ref error_msg, tran);

                if ((dsresult == null) || (dsresult.Tables.Count <= 0) || (dsresult.Tables[0].Rows.Count != 1))
                {
                    tran.Rollback();
                    tranutil.CloseConnection();
                    return null;
                }

                int indexs = 0;

                if (Int32.TryParse(dsresult.Tables[0].Rows[0]["indexs"].ToString(), out indexs) == false)
                {
                    tran.Rollback();
                    tranutil.CloseConnection();
                    return null;
                }

                tran.Commit();
                tranutil.CloseConnection();

                return (dsresult.Tables[0].Rows[0]["Codeing"].ToString() + indexs.ToString()).Trim().ToString();
            }
        }


        /// <summary>
        /// 取得部门编码的流水号
        /// </summary>
        /// <param name="connectionString"></param>
        /// <param name="error_msg"></param>
        /// <returns></returns>
        public static string SCR_DepartmentID(string connectionString, ref string error_msg)
        {
            using (edowork.com.SQL2005.TranUtil tranutil = new TranUtil(connectionString))
            {
                System.Data.SqlClient.SqlTransaction tran = null;

                try
                {
                    tran = tranutil.GetSqlTransaction();
                }
                catch (Exception er)
                {
                    error_msg = er.Message;
                    return null;
                }

                edowork.com.SQL2005.Execute exec = new Execute(connectionString);

                string sql = "";
                int result = -1;

                //更新流水号加1
                sql = "update SCR set indexs = indexs + 1 where Remark='部门编码'";

                result = exec.ExecSQLQueryInt(sql, ref error_msg, tran);

                if (result <= 0)
                {
                    tran.Rollback();
                    tranutil.CloseConnection();
                    return null;
                }

                //取得流水号
                sql = "select * from SCR where Remark='部门编码'";

                DataSet dsresult = exec.ExecSQLQueryDataSet(sql, ref error_msg, tran);

                if ((dsresult == null) || (dsresult.Tables.Count <= 0) || (dsresult.Tables[0].Rows.Count != 1))
                {
                    tran.Rollback();
                    tranutil.CloseConnection();
                    return null;
                }

                int indexs = 0;

                if (Int32.TryParse(dsresult.Tables[0].Rows[0]["indexs"].ToString(), out indexs) == false)
                {
                    tran.Rollback();
                    tranutil.CloseConnection();
                    return null;
                }

                tran.Commit();
                tranutil.CloseConnection();

                return (dsresult.Tables[0].Rows[0]["Codeing"].ToString() + indexs.ToString()).Trim().ToString();
            }
        }


        /// <summary>
        /// 取得职务编码的流水号
        /// </summary>
        /// <param name="connectionString"></param>
        /// <param name="error_msg"></param>
        /// <returns></returns>
        public static string SCR_JobID(string connectionString, ref string error_msg)
        {
            using (edowork.com.SQL2005.TranUtil tranutil = new TranUtil(connectionString))
            {
                System.Data.SqlClient.SqlTransaction tran = null;

                try
                {
                    tran = tranutil.GetSqlTransaction();
                }
                catch (Exception er)
                {
                    error_msg = er.Message;
                    return null;
                }

                edowork.com.SQL2005.Execute exec = new Execute(connectionString);

                string sql = "";
                int result = -1;

                //更新流水号加1
                sql = "update SCR set indexs = indexs + 1 where Remark='职务编码'";

                result = exec.ExecSQLQueryInt(sql, ref error_msg, tran);

                if (result <= 0)
                {
                    tran.Rollback();
                    tranutil.CloseConnection();
                    return null;
                }

                //取得流水号
                sql = "select * from SCR where Remark='职务编码'";

                DataSet dsresult = exec.ExecSQLQueryDataSet(sql, ref error_msg, tran);

                if ((dsresult == null) || (dsresult.Tables.Count <= 0) || (dsresult.Tables[0].Rows.Count != 1))
                {
                    tran.Rollback();
                    tranutil.CloseConnection();
                    return null;
                }

                int indexs = 0;

                if (Int32.TryParse(dsresult.Tables[0].Rows[0]["indexs"].ToString(), out indexs) == false)
                {
                    tran.Rollback();
                    tranutil.CloseConnection();
                    return null;
                }

                tran.Commit();
                tranutil.CloseConnection();

                return (dsresult.Tables[0].Rows[0]["Codeing"].ToString() + indexs.ToString()).Trim().ToString();
            }
        }


        /// <summary>
        /// 取得信用等级编码的流水号
        /// </summary>
        /// <param name="connectionString"></param>
        /// <param name="error_msg"></param>
        /// <returns></returns>
        public static string SCR_CreditID(string connectionString, ref string error_msg)
        {
            using (edowork.com.SQL2005.TranUtil tranutil = new TranUtil(connectionString))
            {
                System.Data.SqlClient.SqlTransaction tran = null;

                try
                {
                    tran = tranutil.GetSqlTransaction();
                }
                catch (Exception er)
                {
                    error_msg = er.Message;
                    return null;
                }

                edowork.com.SQL2005.Execute exec = new Execute(connectionString);

                string sql = "";
                int result = -1;

                //更新流水号加1
                sql = "update SCR set indexs = indexs + 1 where Remark='信用等级'";

                result = exec.ExecSQLQueryInt(sql, ref error_msg, tran);

                if (result <= 0)
                {
                    tran.Rollback();
                    tranutil.CloseConnection();
                    return null;
                }

                //取得流水号
                sql = "select * from SCR where Remark='信用等级'";

                DataSet dsresult = exec.ExecSQLQueryDataSet(sql, ref error_msg, tran);

                if ((dsresult == null) || (dsresult.Tables.Count <= 0) || (dsresult.Tables[0].Rows.Count != 1))
                {
                    tran.Rollback();
                    tranutil.CloseConnection();
                    return null;
                }

                int indexs = 0;

                if (Int32.TryParse(dsresult.Tables[0].Rows[0]["indexs"].ToString(), out indexs) == false)
                {
                    tran.Rollback();
                    tranutil.CloseConnection();
                    return null;
                }

                tran.Commit();
                tranutil.CloseConnection();

                return (dsresult.Tables[0].Rows[0]["Codeing"].ToString() + indexs.ToString()).Trim().ToString();
            }
        }

        /// <summary>
        /// 取得结算方式编码的流水号
        /// </summary>
        /// <param name="connectionString"></param>
        /// <param name="error_msg"></param>
        /// <returns></returns>
        public static string SCR_SettleID(string connectionString, ref string error_msg)
        {
            using (edowork.com.SQL2005.TranUtil tranutil = new TranUtil(connectionString))
            {
                System.Data.SqlClient.SqlTransaction tran = null;

                try
                {
                    tran = tranutil.GetSqlTransaction();
                }
                catch (Exception er)
                {
                    error_msg = er.Message;
                    return null;
                }

                edowork.com.SQL2005.Execute exec = new Execute(connectionString);

                string sql = "";
                int result = -1;

                //更新流水号加1
                sql = "update SCR set indexs = indexs + 1 where Remark='结算方式'";

                result = exec.ExecSQLQueryInt(sql, ref error_msg, tran);

                if (result <= 0)
                {
                    tran.Rollback();
                    tranutil.CloseConnection();
                    return null;
                }

                //取得流水号
                sql = "select * from SCR where Remark='结算方式'";

                DataSet dsresult = exec.ExecSQLQueryDataSet(sql, ref error_msg, tran);

                if ((dsresult == null) || (dsresult.Tables.Count <= 0) || (dsresult.Tables[0].Rows.Count != 1))
                {
                    tran.Rollback();
                    tranutil.CloseConnection();
                    return null;
                }

                int indexs = 0;

                if (Int32.TryParse(dsresult.Tables[0].Rows[0]["indexs"].ToString(), out indexs) == false)
                {
                    tran.Rollback();
                    tranutil.CloseConnection();
                    return null;
                }

                tran.Commit();
                tranutil.CloseConnection();

                return (dsresult.Tables[0].Rows[0]["Codeing"].ToString() + indexs.ToString()).Trim().ToString();
            }
        }


        /// <summary>
        /// 取得运输方式编码的流水号
        /// </summary>
        /// <param name="connectionString"></param>
        /// <param name="error_msg"></param>
        /// <returns></returns>
        public static string SCR_TransportID(string connectionString, ref string error_msg)
        {
            using (edowork.com.SQL2005.TranUtil tranutil = new TranUtil(connectionString))
            {
                System.Data.SqlClient.SqlTransaction tran = null;

                try
                {
                    tran = tranutil.GetSqlTransaction();
                }
                catch (Exception er)
                {
                    error_msg = er.Message;
                    return null;
                }

                edowork.com.SQL2005.Execute exec = new Execute(connectionString);

                string sql = "";
                int result = -1;

                //更新流水号加1
                sql = "update SCR set indexs = indexs + 1 where Remark='运输方式'";

                result = exec.ExecSQLQueryInt(sql, ref error_msg, tran);

                if (result <= 0)
                {
                    tran.Rollback();
                    tranutil.CloseConnection();
                    return null;
                }

                //取得流水号
                sql = "select * from SCR where Remark='运输方式'";

                DataSet dsresult = exec.ExecSQLQueryDataSet(sql, ref error_msg, tran);

                if ((dsresult == null) || (dsresult.Tables.Count <= 0) || (dsresult.Tables[0].Rows.Count != 1))
                {
                    tran.Rollback();
                    tranutil.CloseConnection();
                    return null;
                }

                int indexs = 0;

                if (Int32.TryParse(dsresult.Tables[0].Rows[0]["indexs"].ToString(), out indexs) == false)
                {
                    tran.Rollback();
                    tranutil.CloseConnection();
                    return null;
                }

                tran.Commit();
                tranutil.CloseConnection();

                return (dsresult.Tables[0].Rows[0]["Codeing"].ToString() + indexs.ToString()).Trim().ToString();
            }
        }


        /// <summary>
        /// 取得产品类别编码的流水号
        /// </summary>
        /// <param name="connectionString"></param>
        /// <param name="error_msg"></param>
        /// <returns></returns>
        public static string SCR_GoodsclassID(string connectionString, ref string error_msg)
        {
            using (edowork.com.SQL2005.TranUtil tranutil = new TranUtil(connectionString))
            {
                System.Data.SqlClient.SqlTransaction tran = null;

                try
                {
                    tran = tranutil.GetSqlTransaction();
                }
                catch (Exception er)
                {
                    error_msg = er.Message;
                    return null;
                }

                edowork.com.SQL2005.Execute exec = new Execute(connectionString);

                string sql = "";
                int result = -1;

                //更新流水号加1
                sql = "update SCR set indexs = indexs + 1 where Remark='产品类别'";

                result = exec.ExecSQLQueryInt(sql, ref error_msg, tran);

                if (result <= 0)
                {
                    tran.Rollback();
                    tranutil.CloseConnection();
                    return null;
                }

                //取得流水号
                sql = "select * from SCR where Remark='产品类别'";

                DataSet dsresult = exec.ExecSQLQueryDataSet(sql, ref error_msg, tran);

                if ((dsresult == null) || (dsresult.Tables.Count <= 0) || (dsresult.Tables[0].Rows.Count != 1))
                {
                    tran.Rollback();
                    tranutil.CloseConnection();
                    return null;
                }

                int indexs = 0;

                if (Int32.TryParse(dsresult.Tables[0].Rows[0]["indexs"].ToString(), out indexs) == false)
                {
                    tran.Rollback();
                    tranutil.CloseConnection();
                    return null;
                }

                tran.Commit();
                tranutil.CloseConnection();

                return (dsresult.Tables[0].Rows[0]["Codeing"].ToString() + indexs.ToString()).Trim().ToString();
            }
        }

        /// <summary>
        /// 取得产品单位编码的流水号
        /// </summary>
        /// <param name="connectionString"></param>
        /// <param name="error_msg"></param>
        /// <returns></returns>
        public static string SCR_GoodsunitID(string connectionString, ref string error_msg)
        {
            using (edowork.com.SQL2005.TranUtil tranutil = new TranUtil(connectionString))
            {
                System.Data.SqlClient.SqlTransaction tran = null;

                try
                {
                    tran = tranutil.GetSqlTransaction();
                }
                catch (Exception er)
                {
                    error_msg = er.Message;
                    return null;
                }

                edowork.com.SQL2005.Execute exec = new Execute(connectionString);

                string sql = "";
                int result = -1;

                //更新流水号加1
                sql = "update SCR set indexs = indexs + 1 where Remark='产品单位'";

                result = exec.ExecSQLQueryInt(sql, ref error_msg, tran);

                if (result <= 0)
                {
                    tran.Rollback();
                    tranutil.CloseConnection();
                    return null;
                }

                //取得流水号
                sql = "select * from SCR where Remark='产品单位'";

                DataSet dsresult = exec.ExecSQLQueryDataSet(sql, ref error_msg, tran);

                if ((dsresult == null) || (dsresult.Tables.Count <= 0) || (dsresult.Tables[0].Rows.Count != 1))
                {
                    tran.Rollback();
                    tranutil.CloseConnection();
                    return null;
                }

                int indexs = 0;

                if (Int32.TryParse(dsresult.Tables[0].Rows[0]["indexs"].ToString(), out indexs) == false)
                {
                    tran.Rollback();
                    tranutil.CloseConnection();
                    return null;
                }

                tran.Commit();
                tranutil.CloseConnection();

                return (dsresult.Tables[0].Rows[0]["Codeing"].ToString() + indexs.ToString()).Trim().ToString();
            }
        }

        /// <summary>
        /// 取得规格描述编码的流水号
        /// </summary>
        /// <param name="connectionString"></param>
        /// <param name="error_msg"></param>
        /// <returns></returns>
        public static string SCR_GoodsspecID(string connectionString, ref string error_msg)
        {
            using (edowork.com.SQL2005.TranUtil tranutil = new TranUtil(connectionString))
            {
                System.Data.SqlClient.SqlTransaction tran = null;

                try
                {
                    tran = tranutil.GetSqlTransaction();
                }
                catch (Exception er)
                {
                    error_msg = er.Message;
                    return null;
                }

                edowork.com.SQL2005.Execute exec = new Execute(connectionString);

                string sql = "";
                int result = -1;

                //更新流水号加1
                sql = "update SCR set indexs = indexs + 1 where Remark='产品规格'";

                result = exec.ExecSQLQueryInt(sql, ref error_msg, tran);

                if (result <= 0)
                {
                    tran.Rollback();
                    tranutil.CloseConnection();
                    return null;
                }

                //取得流水号
                sql = "select * from SCR where Remark='产品规格'";

                DataSet dsresult = exec.ExecSQLQueryDataSet(sql, ref error_msg, tran);

                if ((dsresult == null) || (dsresult.Tables.Count <= 0) || (dsresult.Tables[0].Rows.Count != 1))
                {
                    tran.Rollback();
                    tranutil.CloseConnection();
                    return null;
                }

                int indexs = 0;

                if (Int32.TryParse(dsresult.Tables[0].Rows[0]["indexs"].ToString(), out indexs) == false)
                {
                    tran.Rollback();
                    tranutil.CloseConnection();
                    return null;
                }

                tran.Commit();
                tranutil.CloseConnection();

                return (dsresult.Tables[0].Rows[0]["Codeing"].ToString() + indexs.ToString()).Trim().ToString();
            }
        }

        /// <summary>
        /// 取得堆放方式编码的流水号
        /// </summary>
        /// <param name="connectionString"></param>
        /// <param name="error_msg"></param>
        /// <returns></returns>
        public static string SCR_StackID(string connectionString, ref string error_msg)
        {
            using (edowork.com.SQL2005.TranUtil tranutil = new TranUtil(connectionString))
            {
                System.Data.SqlClient.SqlTransaction tran = null;

                try
                {
                    tran = tranutil.GetSqlTransaction();
                }
                catch (Exception er)
                {
                    error_msg = er.Message;
                    return null;
                }

                edowork.com.SQL2005.Execute exec = new Execute(connectionString);

                string sql = "";
                int result = -1;

                //更新流水号加1
                sql = "update SCR set indexs = indexs + 1 where Remark='堆放方式'";

                result = exec.ExecSQLQueryInt(sql, ref error_msg, tran);

                if (result <= 0)
                {
                    tran.Rollback();
                    tranutil.CloseConnection();
                    return null;
                }

                //取得流水号
                sql = "select * from SCR where Remark='堆放方式'";

                DataSet dsresult = exec.ExecSQLQueryDataSet(sql, ref error_msg, tran);

                if ((dsresult == null) || (dsresult.Tables.Count <= 0) || (dsresult.Tables[0].Rows.Count != 1))
                {
                    tran.Rollback();
                    tranutil.CloseConnection();
                    return null;
                }

                int indexs = 0;

                if (Int32.TryParse(dsresult.Tables[0].Rows[0]["indexs"].ToString(), out indexs) == false)
                {
                    tran.Rollback();
                    tranutil.CloseConnection();
                    return null;
                }

                tran.Commit();
                tranutil.CloseConnection();

                return (dsresult.Tables[0].Rows[0]["Codeing"].ToString() + indexs.ToString()).Trim().ToString();
            }
        }

        /// <summary>
        /// 取得防护方式编码的流水号
        /// </summary>
        /// <param name="connectionString"></param>
        /// <param name="error_msg"></param>
        /// <returns></returns>
        public static string SCR_GuardID(string connectionString, ref string error_msg)
        {
            using (edowork.com.SQL2005.TranUtil tranutil = new TranUtil(connectionString))
            {
                System.Data.SqlClient.SqlTransaction tran = null;

                try
                {
                    tran = tranutil.GetSqlTransaction();
                }
                catch (Exception er)
                {
                    error_msg = er.Message;
                    return null;
                }

                edowork.com.SQL2005.Execute exec = new Execute(connectionString);

                string sql = "";
                int result = -1;

                //更新流水号加1
                sql = "update SCR set indexs = indexs + 1 where Remark='防护方式'";

                result = exec.ExecSQLQueryInt(sql, ref error_msg, tran);

                if (result <= 0)
                {
                    tran.Rollback();
                    tranutil.CloseConnection();
                    return null;
                }

                //取得流水号
                sql = "select * from SCR where Remark='防护方式'";

                DataSet dsresult = exec.ExecSQLQueryDataSet(sql, ref error_msg, tran);

                if ((dsresult == null) || (dsresult.Tables.Count <= 0) || (dsresult.Tables[0].Rows.Count != 1))
                {
                    tran.Rollback();
                    tranutil.CloseConnection();
                    return null;
                }

                int indexs = 0;

                if (Int32.TryParse(dsresult.Tables[0].Rows[0]["indexs"].ToString(), out indexs) == false)
                {
                    tran.Rollback();
                    tranutil.CloseConnection();
                    return null;
                }

                tran.Commit();
                tranutil.CloseConnection();

                return (dsresult.Tables[0].Rows[0]["Codeing"].ToString() + indexs.ToString()).Trim().ToString();
            }
        }

        /// <summary>
        /// 取得供应商编码的流水号
        /// </summary>
        /// <param name="connectionString"></param>
        /// <param name="error_msg"></param>
        /// <returns></returns>
        public static string SCR_SupplierID(string connectionString, ref string error_msg)
        {
            using (edowork.com.SQL2005.TranUtil tranutil = new TranUtil(connectionString))
            {
                System.Data.SqlClient.SqlTransaction tran = null;

                try
                {
                    tran = tranutil.GetSqlTransaction();
                }
                catch (Exception er)
                {
                    error_msg = er.Message;
                    return null;
                }

                edowork.com.SQL2005.Execute exec = new Execute(connectionString);

                string sql = "";
                int result = -1;

                //更新流水号加1
                sql = "update SCR set indexs = indexs + 1 where Remark='供应商'";

                result = exec.ExecSQLQueryInt(sql, ref error_msg, tran);

                if (result <= 0)
                {
                    tran.Rollback();
                    tranutil.CloseConnection();
                    return null;
                }

                //取得流水号
                sql = "select * from SCR where Remark='供应商'";

                DataSet dsresult = exec.ExecSQLQueryDataSet(sql, ref error_msg, tran);

                if ((dsresult == null) || (dsresult.Tables.Count <= 0) || (dsresult.Tables[0].Rows.Count != 1))
                {
                    tran.Rollback();
                    tranutil.CloseConnection();
                    return null;
                }

                int indexs = 0;

                if (Int32.TryParse(dsresult.Tables[0].Rows[0]["indexs"].ToString(), out indexs) == false)
                {
                    tran.Rollback();
                    tranutil.CloseConnection();
                    return null;
                }

                tran.Commit();
                tranutil.CloseConnection();

                return (dsresult.Tables[0].Rows[0]["Codeing"].ToString() + indexs.ToString()).Trim().ToString();
            }
        }

        /// <summary>
        /// 取得客户编码的流水号
        /// </summary>
        /// <param name="connectionString"></param>
        /// <param name="error_msg"></param>
        /// <returns></returns>
        public static string SCR_CustomerID(string connectionString, ref string error_msg)
        {
            using (edowork.com.SQL2005.TranUtil tranutil = new TranUtil(connectionString))
            {
                System.Data.SqlClient.SqlTransaction tran = null;

                try
                {
                    tran = tranutil.GetSqlTransaction();
                }
                catch (Exception er)
                {
                    error_msg = er.Message;
                    return null;
                }

                edowork.com.SQL2005.Execute exec = new Execute(connectionString);

                string sql = "";
                int result = -1;

                //更新流水号加1
                sql = "update SCR set indexs = indexs + 1 where Remark='客户'";

                result = exec.ExecSQLQueryInt(sql, ref error_msg, tran);

                if (result <= 0)
                {
                    tran.Rollback();
                    tranutil.CloseConnection();
                    return null;
                }

                //取得流水号
                sql = "select * from SCR where Remark='客户'";

                DataSet dsresult = exec.ExecSQLQueryDataSet(sql, ref error_msg, tran);

                if ((dsresult == null) || (dsresult.Tables.Count <= 0) || (dsresult.Tables[0].Rows.Count != 1))
                {
                    tran.Rollback();
                    tranutil.CloseConnection();
                    return null;
                }

                int indexs = 0;

                if (Int32.TryParse(dsresult.Tables[0].Rows[0]["indexs"].ToString(), out indexs) == false)
                {
                    tran.Rollback();
                    tranutil.CloseConnection();
                    return null;
                }

                tran.Commit();
                tranutil.CloseConnection();

                return (dsresult.Tables[0].Rows[0]["Codeing"].ToString() + indexs.ToString()).Trim().ToString();
            }
        }

        /// <summary>
        /// 取得采购计划单的流水号
        /// </summary>
        /// <param name="connectionString"></param>
        /// <param name="error_msg"></param>
        /// <returns></returns>
        public static string SCR_PurchaseplanID(string connectionString, ref string error_msg)
        {
            using (edowork.com.SQL2005.TranUtil tranutil = new TranUtil(connectionString))
            {
                System.Data.SqlClient.SqlTransaction tran = null;

                try
                {
                    tran = tranutil.GetSqlTransaction();
                }
                catch (Exception er)
                {
                    error_msg = er.Message;
                    return null;
                }

                edowork.com.SQL2005.Execute exec = new Execute(connectionString);

                string sql = "";
                int result = -1;

                //更新流水号加1
                sql = "update SCR set indexs = indexs + 1 where Remark='采购计划'";

                result = exec.ExecSQLQueryInt(sql, ref error_msg, tran);

                if (result <= 0)
                {
                    tran.Rollback();
                    tranutil.CloseConnection();
                    return null;
                }

                //取得流水号
                sql = "select * from SCR where Remark='采购计划'";

                DataSet dsresult = exec.ExecSQLQueryDataSet(sql, ref error_msg, tran);

                if ((dsresult == null) || (dsresult.Tables.Count <= 0) || (dsresult.Tables[0].Rows.Count != 1))
                {
                    tran.Rollback();
                    tranutil.CloseConnection();
                    return null;
                }

                int indexs = 0;

                if (Int32.TryParse(dsresult.Tables[0].Rows[0]["indexs"].ToString(), out indexs) == false)
                {
                    tran.Rollback();
                    tranutil.CloseConnection();
                    return null;
                }

                tran.Commit();
                tranutil.CloseConnection();

                return (dsresult.Tables[0].Rows[0]["Codeing"].ToString() + indexs.ToString()).Trim().ToString();
            }
        }


        /// <summary>
        /// 取得采购单的流水号
        /// </summary>
        /// <param name="connectionString"></param>
        /// <param name="error_msg"></param>
        /// <returns></returns>
        public static string SCR_PurchaseID(string connectionString, ref string error_msg)
        {
            using (edowork.com.SQL2005.TranUtil tranutil = new TranUtil(connectionString))
            {
                System.Data.SqlClient.SqlTransaction tran = null;

                try
                {
                    tran = tranutil.GetSqlTransaction();
                }
                catch (Exception er)
                {
                    error_msg = er.Message;
                    return null;
                }

                edowork.com.SQL2005.Execute exec = new Execute(connectionString);

                string sql = "";
                int result = -1;

                //更新流水号加1
                sql = "update SCR set indexs = indexs + 1 where Remark='采购单'";

                result = exec.ExecSQLQueryInt(sql, ref error_msg, tran);

                if (result <= 0)
                {
                    tran.Rollback();
                    tranutil.CloseConnection();
                    return null;
                }

                //取得流水号
                sql = "select * from SCR where Remark='采购单'";

                DataSet dsresult = exec.ExecSQLQueryDataSet(sql, ref error_msg, tran);

                if ((dsresult == null) || (dsresult.Tables.Count <= 0) || (dsresult.Tables[0].Rows.Count != 1))
                {
                    tran.Rollback();
                    tranutil.CloseConnection();
                    return null;
                }

                int indexs = 0;

                if (Int32.TryParse(dsresult.Tables[0].Rows[0]["indexs"].ToString(), out indexs) == false)
                {
                    tran.Rollback();
                    tranutil.CloseConnection();
                    return null;
                }

                tran.Commit();
                tranutil.CloseConnection();

                return (dsresult.Tables[0].Rows[0]["Codeing"].ToString() + indexs.ToString()).Trim().ToString();
            }
        }

        /// <summary>
        /// 取得销售单的流水号
        /// </summary>
        /// <param name="connectionString"></param>
        /// <param name="error_msg"></param>
        /// <returns></returns>
        public static string SCR_SaleID(string connectionString, ref string error_msg)
        {
            using (edowork.com.SQL2005.TranUtil tranutil = new TranUtil(connectionString))
            {
                System.Data.SqlClient.SqlTransaction tran = null;

                try
                {
                    tran = tranutil.GetSqlTransaction();
                }
                catch (Exception er)
                {
                    error_msg = er.Message;
                    return null;
                }

                edowork.com.SQL2005.Execute exec = new Execute(connectionString);

                string sql = "";
                int result = -1;

                //更新流水号加1
                sql = "update SCR set indexs = indexs + 1 where Remark='销售单'";

                result = exec.ExecSQLQueryInt(sql, ref error_msg, tran);

                if (result <= 0)
                {
                    tran.Rollback();
                    tranutil.CloseConnection();
                    return null;
                }

                //取得流水号
                sql = "select * from SCR where Remark='销售单'";

                DataSet dsresult = exec.ExecSQLQueryDataSet(sql, ref error_msg, tran);

                if ((dsresult == null) || (dsresult.Tables.Count <= 0) || (dsresult.Tables[0].Rows.Count != 1))
                {
                    tran.Rollback();
                    tranutil.CloseConnection();
                    return null;
                }

                int indexs = 0;

                if (Int32.TryParse(dsresult.Tables[0].Rows[0]["indexs"].ToString(), out indexs) == false)
                {
                    tran.Rollback();
                    tranutil.CloseConnection();
                    return null;
                }

                tran.Commit();
                tranutil.CloseConnection();

                return (dsresult.Tables[0].Rows[0]["Codeing"].ToString() + indexs.ToString()).Trim().ToString();
            }
        }

        /// <summary>
        /// 取得销售计划单的流水号
        /// </summary>
        /// <param name="connectionString"></param>
        /// <param name="error_msg"></param>
        /// <returns></returns>
        public static string SCR_SaleplanID(string connectionString, ref string error_msg)
        {
            using (edowork.com.SQL2005.TranUtil tranutil = new TranUtil(connectionString))
            {
                System.Data.SqlClient.SqlTransaction tran = null;

                try
                {
                    tran = tranutil.GetSqlTransaction();
                }
                catch (Exception er)
                {
                    error_msg = er.Message;
                    return null;
                }

                edowork.com.SQL2005.Execute exec = new Execute(connectionString);

                string sql = "";
                int result = -1;

                //更新流水号加1
                sql = "update SCR set indexs = indexs + 1 where Remark='销售计划'";

                result = exec.ExecSQLQueryInt(sql, ref error_msg, tran);

                if (result <= 0)
                {
                    tran.Rollback();
                    tranutil.CloseConnection();
                    return null;
                }

                //取得流水号
                sql = "select * from SCR where Remark='销售计划'";

                DataSet dsresult = exec.ExecSQLQueryDataSet(sql, ref error_msg, tran);

                if ((dsresult == null) || (dsresult.Tables.Count <= 0) || (dsresult.Tables[0].Rows.Count != 1))
                {
                    tran.Rollback();
                    tranutil.CloseConnection();
                    return null;
                }

                int indexs = 0;

                if (Int32.TryParse(dsresult.Tables[0].Rows[0]["indexs"].ToString(), out indexs) == false)
                {
                    tran.Rollback();
                    tranutil.CloseConnection();
                    return null;
                }

                tran.Commit();
                tranutil.CloseConnection();

                return (dsresult.Tables[0].Rows[0]["Codeing"].ToString() + indexs.ToString()).Trim().ToString();
            }
        }


        /// <summary>
        /// 取得仓库单的流水号
        /// </summary>
        /// <param name="connectionString"></param>
        /// <param name="error_msg"></param>
        /// <returns></returns>
        public static string SCR_BillID(string connectionString, ref string error_msg)
        {
            using (edowork.com.SQL2005.TranUtil tranutil = new TranUtil(connectionString))
            {
                System.Data.SqlClient.SqlTransaction tran = null;

                try
                {
                    tran = tranutil.GetSqlTransaction();
                }
                catch (Exception er)
                {
                    error_msg = er.Message;
                    return null;
                }

                edowork.com.SQL2005.Execute exec = new Execute(connectionString);

                string sql = "";
                int result = -1;

                //更新流水号加1
                sql = "update SCR set indexs = indexs + 1 where Remark='仓库单'";

                result = exec.ExecSQLQueryInt(sql, ref error_msg, tran);

                if (result <= 0)
                {
                    tran.Rollback();
                    tranutil.CloseConnection();
                    return null;
                }

                //取得流水号
                sql = "select * from SCR where Remark='仓库单'";

                DataSet dsresult = exec.ExecSQLQueryDataSet(sql, ref error_msg, tran);

                if ((dsresult == null) || (dsresult.Tables.Count <= 0) || (dsresult.Tables[0].Rows.Count != 1))
                {
                    tran.Rollback();
                    tranutil.CloseConnection();
                    return null;
                }

                int indexs = 0;

                if (Int32.TryParse(dsresult.Tables[0].Rows[0]["indexs"].ToString(), out indexs) == false)
                {
                    tran.Rollback();
                    tranutil.CloseConnection();
                    return null;
                }

                tran.Commit();
                tranutil.CloseConnection();

                return (dsresult.Tables[0].Rows[0]["Codeing"].ToString() + indexs.ToString()).Trim().ToString();
            }
        }

        /// <summary>
        /// 取得盘点单的流水号
        /// </summary>
        /// <param name="connectionString"></param>
        /// <param name="error_msg"></param>
        /// <returns></returns>
        public static string SCR_CSID(string connectionString, ref string error_msg)
        {
            using (edowork.com.SQL2005.TranUtil tranutil = new TranUtil(connectionString))
            {
                System.Data.SqlClient.SqlTransaction tran = null;

                try
                {
                    tran = tranutil.GetSqlTransaction();
                }
                catch (Exception er)
                {
                    error_msg = er.Message;
                    return null;
                }

                edowork.com.SQL2005.Execute exec = new Execute(connectionString);

                string sql = "";
                int result = -1;

                //更新流水号加1
                sql = "update SCR set indexs = indexs + 1 where Remark='盘点单'";

                result = exec.ExecSQLQueryInt(sql, ref error_msg, tran);

                if (result <= 0)
                {
                    tran.Rollback();
                    tranutil.CloseConnection();
                    return null;
                }

                //取得流水号
                sql = "select * from SCR where Remark='盘点单'";

                DataSet dsresult = exec.ExecSQLQueryDataSet(sql, ref error_msg, tran);

                if ((dsresult == null) || (dsresult.Tables.Count <= 0) || (dsresult.Tables[0].Rows.Count != 1))
                {
                    tran.Rollback();
                    tranutil.CloseConnection();
                    return null;
                }

                int indexs = 0;

                if (Int32.TryParse(dsresult.Tables[0].Rows[0]["indexs"].ToString(), out indexs) == false)
                {
                    tran.Rollback();
                    tranutil.CloseConnection();
                    return null;
                }

                tran.Commit();
                tranutil.CloseConnection();

                return (dsresult.Tables[0].Rows[0]["Codeing"].ToString() + indexs.ToString()).Trim().ToString();
            }
        }

        /// <summary>
        /// 取得调整单的流水号
        /// </summary>
        /// <param name="connectionString"></param>
        /// <param name="error_msg"></param>
        /// <returns></returns>
        public static string SCR_LJID(string connectionString, ref string error_msg)
        {
            using (edowork.com.SQL2005.TranUtil tranutil = new TranUtil(connectionString))
            {
                System.Data.SqlClient.SqlTransaction tran = null;

                try
                {
                    tran = tranutil.GetSqlTransaction();
                }
                catch (Exception er)
                {
                    error_msg = er.Message;
                    return null;
                }

                edowork.com.SQL2005.Execute exec = new Execute(connectionString);

                string sql = "";
                int result = -1;

                //更新流水号加1
                sql = "update SCR set indexs = indexs + 1 where Remark='调整单'";

                result = exec.ExecSQLQueryInt(sql, ref error_msg, tran);

                if (result <= 0)
                {
                    tran.Rollback();
                    tranutil.CloseConnection();
                    return null;
                }

                //取得流水号
                sql = "select * from SCR where Remark='调整单'";

                DataSet dsresult = exec.ExecSQLQueryDataSet(sql, ref error_msg, tran);

                if ((dsresult == null) || (dsresult.Tables.Count <= 0) || (dsresult.Tables[0].Rows.Count != 1))
                {
                    tran.Rollback();
                    tranutil.CloseConnection();
                    return null;
                }

                int indexs = 0;

                if (Int32.TryParse(dsresult.Tables[0].Rows[0]["indexs"].ToString(), out indexs) == false)
                {
                    tran.Rollback();
                    tranutil.CloseConnection();
                    return null;
                }

                tran.Commit();
                tranutil.CloseConnection();

                return (dsresult.Tables[0].Rows[0]["Codeing"].ToString() + indexs.ToString()).Trim().ToString();
            }
        }
    }
}